package sivak.net.proc.dyn.double_lib;

/**
 * Created with IntelliJ IDEA.
 * User: ZefiR
 * Date: 25.01.13
 * Time: 22:30
 * To change this template use File | Settings | File Templates.
 */
public class TestDoubleLib {
    public static void main(String[] args) {
        int len = 10;
        DoubleNode tail = new DoubleNode(len, null, null);
        DoubleNode head = generateRec(len - 1, tail);
        //Добавление в конец
        printDoubleLL(tail);
        head = DoubleLLUtils.add(tail, 100);
        System.out.println();
        printDoubleLL(tail);
        //Удаление последнего элемента
        head = DoubleLLUtils.remove(tail);
        System.out.println();
        printDoubleLL(tail);
        //Добавление по индексу
        tail = DoubleLLUtils.add(tail, 3, 200);
        System.out.println();
        printDoubleLL(tail);
        //Удаление по индексу
        head = DoubleLLUtils.remove(tail, 3);
        System.out.println();
        printDoubleLL(tail);
    }

    public static DoubleNode generateRec(int length, DoubleNode head) {
        if (length == 1) {
            head.next = new DoubleNode(length, head, null);
            return head.next;
        }
        head.next =  new DoubleNode(length, head, null);
        return generateRec(length - 1, head.next);
    }

    public static void printDoubleLL(DoubleNode tail) {
        System.out.print(" " + tail.value);
        if (tail.next != null)
            printDoubleLL(tail.next);
    }
}
